package com.shy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class OrderController {
    @Autowired
    StringRedisTemplate redisTemplate;


    public String deductStock(@PathVariable String productId) {
        String lockKey = "product_" + productId;

        redisTemplate.opsForValue().setIfAbsent(lockKey, "lock", 30, TimeUnit.SECONDS);
        return "";
    }
}
